package com.ficus.road.maintain.core.infrastructure.mongo.converter;

import com.mongodb.BasicDBObject;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;

import java.util.regex.Pattern;

/**
 * @author siyuan.li
 * @date 2020/3/30
 */
@WritingConverter
public class PatternConverter implements Converter<Pattern, Object> {

    private static final String REGEX = "$regex";

    @Override
    public Object convert(Pattern pattern) {
        BasicDBObject bson = new BasicDBObject();
        bson.put(REGEX, pattern.toString());
        return bson;
    }
}